<?php

include '../source/config.php';
include '../source/soap.fnc.php';
include '../source/mysql.cls.php';


$data = $arr = array();
$list = $row = array();


//print_r ( $soap->__getFunctions () );//获取服务器上提供的方法
//print_r ( $soap->__getTypes () );//获取服务器上数据类型
	
if(!empty($phone_code) && !empty($uuid)){
	
	

	//获取订单号
	$db = new db_mysql();
	$db->connect($dbhost, $dbuser, $dbpw, $dbname);
	$tmp = $db->do_one('checkMobile', 'id,startCost', 'uuid="'.$uuid.'" and mobile="'.$phone_code.'"');

if(empty($tmp['id'])){ die(); }
	//先预定
	$mid = $tmp['id'];
	$order_sn = $order_pre.$mid;
	
	$customer = array(
		'address'=>$addr,
		'name'=>$name,
		'phone'=>$tel,
		'cardId'=>0,
	);
	$soap = start_soap($wsdl_url['MTS']);
	
	$arr = array(
	'uuid'=>$uuid,
	'orderSn'=>$order_sn,
	'mobile'=>$phone_code,
	'customer'=>$customer,
	
	);
	
	
	$result = $soap->bookMobile($arr);
	
	//print_r($result);
	//$arr['err'] = 1;
	//$arr['errinfo'] = $type;
	
	
	if($result->resultMsg != 100){//预定成功
		$msg = array('err'=>1,'errinfo'=>$result->resultMsg);
		echo json_encode($msg);die();
	} else {
		
	
	
	
$soap = start_soap($wsdl_url['OTS']);

$amount = $tmp['startCost'];	
$data['createDate'] = date("Y-m-d H:i:s");
$data['orderSN'] = $order_sn;
$data['quantity'] = 1;
$data['amount'] = $amount;
$data['areaId'] = $area;
$data['agentId'] = $agentId;
$data['partnerOrderType'] = $partnerOrderType;
$data['paymentStatus'] = 0;
$data['isMobileTiaohao'] = 1;

$orderarr = $data;

$data['consignee'] = 
	array(
		'name'=>$name,
		'address'=>$addr,
		'mobile'=>$tel,
		'phone'=>$phone,
		'zipCode'=>$zip,
		'email'=>'',
		'remark'=>'',
	);


$data['orderItems'] = array();
$data['orderItems'][0] = 
	array(
		'mobile' => $phone_code,
		'monthFee' => $pa, //月费不能为空!
		'suitName' => $pa,//资费名称
		'onNetLong' => 2,//合约期不能为空!
		'firstFeeType' => $bc,// 0,1,2入网当月资费处理方式不能为空!
		'userName' => $name,
		'sfz' => $sfcode,
		'color' => '',
		'itemTitle' => 'diy号码'.$phone_code,//商品名称 不能为空!
		'price' => $amount,
		'amount' => $amount,
		'quantity' => 1,
		'remark' => '',
		'goodsType' => 0,//0选号,1预存话费送手机
		'mobileUUID' => $uuid,
);
$arr['order'] = $data;
//print_r($data);
	$result = $soap->saveOrder($arr);
	
	//print_r($result);
	
	//

	if(!empty($result->result) && $result->result ==100){
		//预定成功
			$db->do_update("checkMobile",array('status'=>1),'id='.$mid);

		//订单信息
		$db->do_insert('orders',$orderarr);

		//收货人信息
		$data['consignee']['orderSN'] = $order_sn;
		$db->do_insert('orders_consignee',$data['consignee']);
		//订单项
		foreach($data['orderItems'] as $val){
			$val['orderSN'] = $order_sn;
			$db->do_insert('orders_item',$val);
		}

			$msg = array(
				'oid'=>$order_sn,
				'phone_grade'=>1,
				'price'=>$amount
				);
			echo json_encode($msg);die();
		
	} else {
		echo $result->result;
	}
}
}
	//echo json_encode($arr);

?>